$(function(){
	var curPage = 1;
    var pageSize = 10;

	var mes = {
		getList: function() {
			$.ajax({
			    url: wsCommon.host + '/api/memberComments/getMsg/' + wsCommon.getUrlParam('commentId'),
			    dataType: wsCommon.jsonType,
			    success: function(res) {
					if(res.code == 1) {
						if(res.result) {
							var data = res.data;
							$('[data-role="title"]').val(data.title);
							$('[data-role="value"]').val(data.commentContent);
						} else {
							wsCommon.setCookie('go_back_link', window.location.href);
							window.location.href = './passport-login.html';
						}
					}
			    },
			    error: function() {
			        // console.log('接口返回失败');
			    }
			})
		},
		sunmit: function() {
			$('[data-role="send"]').on('click', function() {
				var title = $('[data-role="title"]').val();
				var value = $('[data-role="value"]').val();
				if(title == '') {
					iosOverlay({
						text: "标题不能为空!",
						duration: 1500
					});
					return;
				}
				if(value == '') {
					iosOverlay({
						text: "内容不能为空!",
						duration: 1500
					});
					return;
				}

				$.ajax({
					url: wsCommon.host + '/api/memberComments/sendMsg',
					dataType: wsCommon.jsonType,
					data: {
						toId: 1,
						title: title,
						commentContent: value,
						hasSent: true,
						commentId: wsCommon.getUrlParam('commentId')
					},
					success: function(res) {
						if(res.code == 1) {
							if(res.result) {
								iosOverlay({
									text: "发送成功!",
									duration: 1500,
									onbeforehide: function() {
										window.location.reload();
									}
								});
							} else {
								iosOverlay({
									text: res.reason,
									duration: 1500
								});
							}
						} else {
							iosOverlay({
								text: res.reason,
								duration: 1500
							});
						}
					},
					error: function() {
						// console.log('登录显示接口返回失败');
					}
				})
			})


			$('[data-role="sendsave"]').on('click', function() {
				var title = $('[data-role="title"]').val();
				var value = $('[data-role="value"]').val();
				if(title == '') {
					iosOverlay({
						text: "标题不能为空!",
						duration: 1500
					});
					return;
				}
				if(value == '') {
					iosOverlay({
						text: "内容不能为空!",
						duration: 1500
					});
					return;
				}

				$.ajax({
					url: wsCommon.host + '/api/memberComments/sendMsg',
					dataType: wsCommon.jsonType,
					data: {
						toId: 1,
						title: title,
						commentContent: value,
						hasSent: false,
						commentId: wsCommon.getUrlParam('commentId')
					},
					success: function(res) {
						if(res.code == 1) {
							if(res.result) {
								iosOverlay({
									text: "保存到草稿箱成功!",
									duration: 1500,
									onbeforehide: function() {
										window.location.reload();
									}
								});
							} else {
								iosOverlay({
									text: res.reason,
									duration: 1500
								});
							}
						} else {
							iosOverlay({
								text: res.reason,
								duration: 1500
							});
						}
					},
					error: function() {
						// console.log('登录显示接口返回失败');
					}
				})
			})
		},
		init: function() {
			this.getList();
			this.sunmit();
		}
	}

	mes.init();
})
